<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Customer extends MY_Controller {
	
    public function __construct()
    {
        parent::__construct();
        $this->checkLogin();
        $this->data['controller'] = 'customer';
        $this->load->model('Mcustomer');
    }
    
    public function savenamedevice()
    {
        $name_edit = $this->getParamString('_name');
        $mac = $this->getParamString('mac');
        $id = $this->getParamString('id');
        $this->checkPermissionDevice($id,1);
        $this->Mcustomer->savenamedeviceDB($name_edit, $mac, $id);
    }
    
    public function dennyallowcustomerdevice()
    {
        $this->checkPermissionDevice($this->getParamString('id'),1);
        die(json_encode($this->Mcustomer->dennyallowcustomerdeviceDb($this->getParamString('mac'), $this->getParamString('id'), $this->getParamInt('type'))));
    }
    
    public function detail()
    {
        $timeget = $this->getParamString('time');
        $this->data['time'] = $timeget ? $timeget : 'Chọn thời gian';
        $this->data['mac'] = $this->getParamString('mac');
        $this->data['id'] = $this->getParamString('id');
        
        $this->data['data'] = $this->Mcustomer->getInfoCustomer($this->data['mac'], $this->data['id']);
        $this->data['charts'] = $this->Mcustomer->getchartsDetail($this->data['time'],$this->data['mac'], $this->data['id']);
        $this->data['action'] = __FUNCTION__;
        $this->load->view('temp/layout', $this->data);
    }
    
    public function index()
    {
        $this->checkLogin();
        $this->data['type'] = $this->getParamString('type');
        $this->data['id'] = ($this->getParamString('_id_device') != 'abc' &&  $this->getParamString('_id_device') != null )? $this->getParamString('_id_device') : $this->getParamString('id');
        $this->data['top_search'] = $this->getParamString('top_search');
        $timeget = $this->getParamString('time');
        $this->data['time'] = $timeget ? $timeget : 'Chọn thời gian';
        
        // bd phan trang cho list.
        $this->load->library('pagination');
        $config['per_page'] = $this->data['_per_page'] = 50;
        $this->data['page'] = $this->data['page_current'] = $this->getParamUri(2, 1);
        $offset = (($this->getParamUri(2, 1) - 1) * $config['per_page']) > 0 ? (($this->getParamUri(2, 1) - 1) * $config['per_page']) : 0;
        $data = $this->Mcustomer->getCustomer($config['per_page'], $offset, $timeget, $this->data['id']);
        $config['base_url'] = base_url($this->uri->segment(1) . '/');
        $config['total_rows'] = $this->data['sumDevice'] = $data['count'];
        $config['uri_segment'] = 2;
        $config['uri_segment_page'] = $this->getParamUri(2, 1);
        $config['suffix'] = '.html';
        $config['use_page_numbers'] = TRUE;
        $config['paramhack'] = '?id='.$this->data['id'].'&time='.$timeget;
        $this->pagination->initialize($config);
        $this->data['data'] = $data['data'];
        
        
        $this->data['info'] = $this->Mcustomer->getInfo($this->data['id']);
        
        $this->data['smart_search'] = $this->getParamString('smart_search');
        $this->data['charts'] = $this->Mcustomer->getcharts($this->data['id'], $timeget, $data['userList']);

        $this->data['networkgroup'] = $this->Mcustomer->getNetWorkGroup();
        $this->data['action'] = __FUNCTION__;
        $this->load->view('temp/layout', $this->data);
    }
    
    
    public function listcustomer()
    {
        $this->checkLogin();
        
        $this->data['top_search'] = $this->getParamString('top_search');
        $this->data['type'] = $this->getParamString('type');
       
        $timeget = $this->getParamString('time');
        $this->data['time'] = $timeget ? $timeget : 'Chọn thời gian';
        
        // bd phan trang cho list.
        $this->load->library('pagination');
        $config['per_page'] = $this->data['_per_page'] = 50;
        $this->data['page'] = $this->data['page_current'] = $this->getParamUri(2, 1);
        $offset = (($this->getParamUri(2, 1) - 1) * $config['per_page']) > 0 ? (($this->getParamUri(2, 1) - 1) * $config['per_page']) : 0;
        $data = $this->Mcustomer->getCustomerList($config['per_page'], $offset, $timeget);
        $config['base_url'] = base_url($this->uri->segment(1) . '/');
        $config['total_rows'] = $this->data['sumDevice'] = $data['count'];
        $config['uri_segment'] = 2;
        $config['uri_segment_page'] = $this->getParamUri(2, 1);
        $config['suffix'] = '.html';
        $config['use_page_numbers'] = TRUE;
        $config['paramhack'] = '?time='.$timeget;
        $this->pagination->initialize($config);
        $this->data['data'] = $data['data'];
        
        
        $this->data['smart_search'] = $this->getParamString('smart_search');
        $this->data['charts'] = $this->Mcustomer->getchartsList($timeget);
        
        $this->data['chartspie'] = $this->Mcustomer->getchartPie($timeget);
        //die(print_r($this->data['chartspie']));
        $this->data['networkgroup'] = $this->Mcustomer->getNetWorkGroup();
        $this->data['action'] = __FUNCTION__;
        $this->load->view('temp/layout', $this->data);
    }
    
    
    public function listdennymember()
    {
        $this->checkLogin();
        $this->data['type'] = $this->getParamString('type');
       
        $timeget = $this->getParamString('time');
        $this->data['time'] = $timeget ? $timeget : 'Chọn thời gian';
        
        // bd phan trang cho list.
        $this->load->library('pagination');
        $config['per_page'] = $this->data['_per_page'] = 50;
        $this->data['page'] = $this->data['page_current'] = $this->getParamUri(2, 1);
        $offset = (($this->getParamUri(2, 1) - 1) * $config['per_page']) > 0 ? (($this->getParamUri(2, 1) - 1) * $config['per_page']) : 0;
        $data = $this->Mcustomer->getCustomerListDenny($config['per_page'], $offset, $timeget);
        $config['base_url'] = base_url($this->uri->segment(1) . '/');
        $config['total_rows'] = $this->data['sumDevice'] = $data['count'];
        $config['uri_segment'] = 2;
        $config['uri_segment_page'] = $this->getParamUri(2, 1);
        $config['suffix'] = '.html';
        $config['use_page_numbers'] = TRUE;
        $config['paramhack'] = '?time='.$timeget;
        $this->pagination->initialize($config);
        $this->data['data'] = $data['data'];
        
        
        $this->data['smart_search'] = $this->getParamString('smart_search');
        $this->data['charts'] = $this->Mcustomer->getchartsListDenny($timeget);
        $this->data['chartspie'] = $this->Mcustomer->getchartPieDenny($timeget);
        //die(print_r($this->data['chartspie']));
        $this->data['networkgroup'] = $this->Mcustomer->getNetWorkGroup();
        $this->data['action'] = __FUNCTION__;
        $this->load->view('temp/layout', $this->data);
    }
    
    public function listallowmember()
    {
        $this->checkLogin();
        $this->data['type'] = $this->getParamString('type');
       
        $timeget = $this->getParamString('time');
        $this->data['time'] = $timeget ? $timeget : 'Chọn thời gian';
        
        // bd phan trang cho list.
        $this->load->library('pagination');
        $config['per_page'] = $this->data['_per_page'] = 50;
        $this->data['page'] = $this->data['page_current'] = $this->getParamUri(2, 1);
        $offset = (($this->getParamUri(2, 1) - 1) * $config['per_page']) > 0 ? (($this->getParamUri(2, 1) - 1) * $config['per_page']) : 0;
        $data = $this->Mcustomer->getCustomerListAllow($config['per_page'], $offset, $timeget);
        $config['base_url'] = base_url($this->uri->segment(1) . '/');
        $config['total_rows'] = $this->data['sumDevice'] = $data['count'];
        $config['uri_segment'] = 2;
        $config['uri_segment_page'] = $this->getParamUri(2, 1);
        $config['suffix'] = '.html';
        $config['use_page_numbers'] = TRUE;
        $config['paramhack'] = '?time='.$timeget;
        $this->pagination->initialize($config);
        $this->data['data'] = $data['data'];
        
        
        $this->data['smart_search'] = $this->getParamString('smart_search');
        $this->data['charts'] = $this->Mcustomer->getchartsListAllow($timeget);
        $this->data['chartspie'] = $this->Mcustomer->getchartPieAllow($timeget);
        //die(print_r($this->data['chartspie']));
        $this->data['networkgroup'] = $this->Mcustomer->getNetWorkGroup();
        $this->data['action'] = __FUNCTION__;
        $this->load->view('temp/layout', $this->data);
    }
    
    public function getprovincedevicemember()
    {
        $this->data['data'] = $this->Mcustomer->getprovincedeviceDB($this->getParamInt('id'), $this->getParamInt('id_g'));
        $this->load->view('temp/'.  strtolower(__CLASS__) .'/'. strtolower(__FUNCTION__) , $this->data);
    }
    public function getdistrictdevicemember()
    {
        $this->data['data'] = $this->Mcustomer->getdistrictdeviceDB($this->getParamInt('id'), $this->getParamInt('id_g'));
        $this->load->view('temp/'.  strtolower(__CLASS__) .'/'. strtolower(__FUNCTION__) , $this->data);
    }
    
    public function getaddressdevicemember()
    {
        $this->data['data'] = $this->Mcustomer->getaddressdevicememberDB($this->getParamInt('id'), $this->getParamInt('id_g'));
        $this->load->view('temp/'.  strtolower(__CLASS__) .'/'. strtolower(__FUNCTION__) , $this->data);
    }
    public function getlistdeviceaddressmember()
    {
        $this->data['data'] = $this->Mcustomer->getlistdeviceaddressmemberDB($this->getParamInt('id'), $this->getParamInt('id_g'));
        $this->load->view('temp/'.  strtolower(__CLASS__) .'/'. strtolower(__FUNCTION__) , $this->data);
    }
    
}
